home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / Fractal / blank.c next >
Encoding:
C/C++ Source or Header  |  1994-10-08  |  2.3 KB  |  117 lines

  1. /*
  2.  *  Copyright (c) 1994 Michael D. Bayne.
  3.  *  All rights reserved.
  4.  *
  5.  *  Please see the documentation accompanying the distribution for distribution
  6.  *  and disclaimer information.
  7.  */
  8.  
  9. #include <exec/memory.h>
  10. #include <intuition/intuition.h>
  11. #include <dos/dos.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <clib/graphics_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include "/Garshnelib/Garshnelib_protos.h"
  19. #include "/Garshnelib/Garshnelib_pragmas.h"
  20.  
  21. #include <math.h>
  22.  
  23. #include "Fractal.h"
  24. #include "//defs.h"
  25. #include "/main.h"
  26.  
  27. struct ModulePrefs
  28. {
  29.     LONG Mode;
  30.     LONG Depth;
  31. };
  32.  
  33. extern struct ModulePrefs nP;
  34.  
  35. struct Screen *ModuleScreen( VOID )
  36. {
  37.     return 0L;
  38. }
  39.  
  40. LONG FracBlank( struct Screen *Scr, UWORD Wid, UWORD Hei )
  41. {
  42.     float x = 0, y = 0, xx, yy, a, b, c;
  43.     LONG i, xe, ye, flg_end = OK, mod = ( 1L << Scr->BitMap.Depth ) - 1;
  44.     struct RastPort *Rast = &( Scr->RastPort );
  45.     
  46.     SetRast( Rast, 0 );
  47.     ScreenToFront( Scr );
  48.     
  49.     a = (float)RangeRand( 1000 ) / 10 - 50.0;
  50.     do
  51.         b = (float)RangeRand( 1000 ) / 10 - 50.0;
  52.     while( b == 0.0 );
  53.     c = (float)RangeRand( 1000 ) / 10 - 50.0;
  54.     
  55.     for( i = 0; i < 50000 && flg_end == OK; i++ )
  56.     {
  57.         if(!( i % 50 ))
  58.         {
  59.             ScreenToFront( Scr );
  60.             flg_end = ContinueBlanking();
  61.         }
  62.         
  63.         if( x < 0 )
  64.             xx = y + sqrt( fabs( b * x - c ));
  65.         else
  66.             xx = y - sqrt( fabs( b * x - c ));
  67.         yy = a - x;
  68.         xe = Wid / 2 + (SHORT)x;
  69.         ye = Hei / 2 + (SHORT)y;
  70.         
  71.         if(( xe >= 0 )&&( ye >= 0 )&&( xe < Wid )&&( ye < Hei ))
  72.         {
  73.             SetAPen( Rast, ( ReadPixel( Rast, xe, ye ) + 1 ) % mod + 1 );
  74.             WritePixel( Rast, xe, ye );
  75.         }
  76.         
  77.         x = xx;
  78.         y = yy;
  79.     }
  80.  
  81.     return flg_end;
  82. }
  83.  
  84. LONG Blank( VOID *Prefs )
  85. {
  86.     struct Screen *Scr;
  87.     struct Window *Wnd;
  88.     struct ModulePrefs *mP;
  89.     LONG RetVal = OK;
  90.     
  91.     if( FractalWnd )
  92.         mP = &nP;
  93.     else
  94.         mP = ( struct ModulePrefs * )Prefs;
  95.  
  96.     Scr = OpenScreenTags( 0L, SA_DisplayID, mP->Mode, SA_Depth, mP->Depth,
  97.                          SA_Overscan, OSCAN_STANDARD, SA_Quiet, TRUE,
  98.                          SA_Behind, TRUE, TAG_DONE );
  99.  
  100.     if( Scr )
  101.     {
  102.         Triplet *ColorTable = RainbowPalette( Scr, 0L, 1L, 0L );
  103.         Wnd = BlankMousePointer( Scr );
  104.         
  105.         while( RetVal == OK )
  106.             RetVal = FracBlank( Scr, Scr->Width, Scr->Height );
  107.         
  108.         UnblankMousePointer( Wnd );
  109.         RainbowPalette( 0L, ColorTable, 1L, 0L );
  110.         CloseScreen( Scr );
  111.     }
  112.     else
  113.         RetVal = FAILED;
  114.  
  115.     return RetVal;
  116. }
  117.